package com.mybatis.mapper;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.mybatis.po.MyUser;
import com.test.AbstractTransactionalTests;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Scanner;

@Service
class UserMapperTest extends AbstractTransactionalTests{
    int userId=11;
    //我不知道怎么输入uid进行修改，所以我把uid定死了 可以直接在这里改uid（（（
    @Autowired
    private UserMapper userMapper;
    @Test
    void testAddAUser() {
        MyUser myUser = new MyUser();
        myUser.setUid(userId);
        myUser.setUname("添加用户测试");
        myUser.setUsex("男");
        //如果测试成功，添加用户方法返回值为1
        assertEquals(1, userMapper.addAUser(myUser), "添加测试失败");
    }
    @Test
    void testUpdateAUser() {
        MyUser myUser = new MyUser();
        myUser.setUid(userId);
        myUser.setUname("修改用户测试");
        myUser.setUsex("女");
        //如果测试成功，修改用户方法返回值为1
        assertEquals(1, userMapper.updateAUser(myUser), "修改测试失败");
    }
    @Test
    void testDeleteAUser() {
        //如果测试成功，删除用户方法返回值为1
        assertEquals(1, userMapper.deleteAUser(userId), "删除测试失败");
    }
    @Test
    void testGetOne() {
        MyUser expectedUser = new MyUser();
        expectedUser.setUid(1);
        expectedUser.setUname("修改用户测试");
        expectedUser.setUsex("女");

        MyUser actualUser = userMapper.getOne(1);
        assertEquals(expectedUser.getUid(), actualUser.getUid(), "查询一个用户测试，uid不匹配");
        assertEquals(expectedUser.getUname(), actualUser.getUname(), "查询一个用户测试，uname不匹配");
        assertEquals(expectedUser.getUsex(), actualUser.getUsex(), "查询一个用户测试，usex不匹配");
    }
    @Test
    void testSelectAllUser() {
        //原代码设有期望值，我删掉了（
        List<MyUser> users = userMapper.selectAllUser();
        for (MyUser user : users) {
            System.out.println(user);
        }
    }
}
